<?php
/**
 * PHPTAL templating engine
 *
 * PHP Version 5
 *
 * @category HTML
 * @package  PHPTAL
 * @author   Laurent Bedubourg <lbedubourg@motion-twin.com>
 * @author   Kornel Lesiński <kornel@aardvarkmedia.co.uk>
 * @license  http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
 * @version  SVN: $Id: Tales.php 591 2009-04-27 23:14:07Z kornel $
 * @link     http://phptal.org/
 */

// Register internal Tales expression modifiers
require_once 'PHPTAL/TalesRegistry.php';
require_once 'PHPTAL/Php/TalesInternal.php';
 
/**
 * TALES Specification 1.3
 *
 *      Expression  ::= [type_prefix ':'] String
 *      type_prefix ::= Name
 *
 * Examples:
 *
 *      a/b/c
 *      path:a/b/c
 *      nothing
 *      path:nothing
 *      python: 1 + 2
 *      string:Hello, ${username}
 *
 *
 * Builtin Names in Page Templates (for PHPTAL)
 *
 *      * nothing - special singleton value used by TAL to represent a
 *        non-value (e.g. void, None, Nil, NULL).
 *
 *      * default - special singleton value used by TAL to specify that
 *        existing text should not be replaced.
 *
 *      * repeat - the repeat variables (see RepeatVariable).
 *
 *
 */
 
 /**
  * translates TALES expression with alternatives into single PHP expression. 
  * Identical to compileExpressionToStatements() for singular expressions.
  *
  * @see PHPTAL_Php_TalesInternal::compileToPHPStatements()
  * @return string
 */
function phptal_tale($expression, $nothrow=false)
{
    return PHPTAL_Php_TalesInternal::compileToPHPExpression($expression,$nothrow);
}

/**
 * returns PHP code that will evaluate given TALES expression.
 * e.g. "string:foo${bar}" may be transformed to "'foo'.phptal_escape($ctx->bar)"
 *
 * Expressions with alternatives ("foo | bar") will cause it to return array
 * Use PHPTAL_Php_TalesInternal::compileToPHPExpression() if you always want string.
 *
 * @param bool $nothrow if true, invalid expression will return NULL (at run time) rather than throwing exception
 * @return string or array
 */
function phptal_tales($expression, $nothrow=false)
{
    return PHPTAL_Php_TalesInternal::compileToPHPStatements($expression,$nothrow);
}

